#!/bin/bash


# 检查 Tomcat 8 是否正在监听 8888 端口
tomcat_dir=/opt/opac3.5_8888
port=8888
nc -z localhost $port
if [ $? -ne 0 ]; then
  echo "Tomcat 8 is not running on port $port"
  # 获取当前 Tomcat 8 进程的 PID
  TOMCAT_PID=$(lsof -i :$port)
  if [ ! -z "$TOMCAT_PID" ]; then
    echo "Killing Tomcat 8 process with PID $TOMCAT_PID"
    # 结束 Tomcat 8 进程
    kill -9 $TOMCAT_PID
  fi
  echo "Starting Tomcat 8"
  # 重启 Tomcat 8 服务
  cd $tomcat_dir
  ./startup.sh
fi

exit 0
